<template>
  <div>
    <span class="search-condition-item-label"
          :title="attr.title">{{ attr.title ? attr.title : '' }}</span>
    <a-select class="search-condition-item-widget"
              :value="newValue"
              @change="onValueChange">
      <a-select-option v-for="item in attr.items"
                       :value="item.value"
                       :key="item.value">{{ item.title }}</a-select-option>
    </a-select>
  </div>
</template>

<script>
  export default {
    props: {
      attr: {
        type: Object,
        default: {
          title: '',
          items: []
        }
      },
      value: {
        type: Object,
        default: null
      }
    },
    data() {
      return {
        newValue: this.value
      };
    },
    watch: {
      value(newVal, oldVal) {
        this.newValue = newVal;
      }
    },
    methods: {
      onValueChange(value) {
        if (this.newValue != value) {
          // this.newValue = value;
          this.$emit('valueChange', { key: this.attr.key, value: value });
        }
      }
    }
  };
</script>

<style lang="scss" scoped>
  ::v-deep .ant-select-selection {
    min-height: 30px;
    height: 30px;
  }
  ::v-deep .ant-select-selection .ant-select-selection__rendered {
    height: 28px;
    line-height: 28px;
  }
</style>
